package net.huashitong.config;


import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.08.16
 */
@Component
public class WeChatPayConfig implements com.github.wxpay.sdk.WXPayConfig {
    /**
     * 微信号
     */
    private static final String DEFAULT_APP_ID = "wxdd4f44c8706d2d88";
    /**
     * 商户号
     */
    private static final String DEFAULT_MCHI_ID = "1227190902";
    /**
     * 商户密匙
     */
    private static final String DEFAULT_KEY = "Ssydt18959215599ssydt18959215599";
    /**
     * 异步通知地址
     */
//    private static final String DEFAULT_NOTIFY_URL = "http://ssydt-test.natapp1.cc/wechat/pay/notify";
    private static final String DEFAULT_NOTIFY_URL = "http://web.ssydt.com/wechat/pay/notify";

    private String appId = DEFAULT_APP_ID;//微信号

    private String mchId = DEFAULT_MCHI_ID;//商户号

    private String key = DEFAULT_KEY ;//商户密匙

    private String notifyUrl = DEFAULT_NOTIFY_URL;//异步通知地址

    private boolean useSandbox = false;//沙箱环境（默认：false）

    private byte[] certData;

    public WeChatPayConfig() {
        super();
        //证书信息暂不处理
//        String certPath = "/path/to/apiclient_cert.p12";
//        File file = new File(certPath);
//        InputStream certStream = certStream = new FileInputStream(file);
//        this.certData = new byte[(int) file.length()];
//        certStream.read(this.certData);
//        certStream.close();
    }

    @Override
    public String getAppID() {
        return this.appId;
    }

    @Override
    public String getMchID() {
        return this.mchId;
    }

    @Override
    public String getKey() {
        return this.key;
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public boolean isUseSandbox() {
        return useSandbox;
    }

    public void setUseSandbox(boolean useSandbox) {
        this.useSandbox = useSandbox;
    }
}
